package com.siwei.mes.entity.experiment.concrete.batch;

import com.alibaba.fastjson.JSONObject;
import com.siwei.mes.common.util.JsonUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 抗渗等级
 *
 * @Description: 抗渗等级  CONCRETE_PARAM_KSDJ
 * @Version: 1.0
 * @author: chenmaolin
 * @date: 2023/12/21 22:29
 */
@Data
@Accessors(chain = true)
public class ConcreteKsdj {
    @ApiModelProperty(value = "龄期")
    private String lq = "";

    @ApiModelProperty(value = "抗渗要求")
    private String ksyq;

    @ApiModelProperty(value = "实测抗渗等级")
    private String ssksdj;

    @ApiModelProperty(value = "检测日期")
    private String jcrq = "";

    @ApiModelProperty(value = "对应抗渗信息")
    private List<KsInfo> ksInfo = new ArrayList();


    @Data
    @Accessors(chain = true)
    @ApiModel("抗渗信息")
    public static class KsInfo {
        @ApiModelProperty(value = "下标")
        private String index = "1";

        @ApiModelProperty(value = "试验压力")
        private String syyl = "";

        @ApiModelProperty(value = "加压时间")
        private String jysj = "";

        @ApiModelProperty(value = "是否渗水1")
        private String sfss1 = "";

        @ApiModelProperty(value = "是否渗水2")
        private String sfss2 = "";

        @ApiModelProperty(value = "是否渗水3")
        private String sfss3 = "";

        @ApiModelProperty(value = "是否渗水4")
        private String sfss4 = "";

        @ApiModelProperty(value = "是否渗水5")
        private String sfss5 = "";

        @ApiModelProperty(value = "是否渗水6")
        private String sfss6 = "";

        @ApiModelProperty(value = "值班人")
        private String zbr = "";
    }

    /**
     * 字符串转成对象 然后再转成json
     *
     * @param object
     * @return
     */
    private static JSONObject toJsonObject(Object object) {
        ConcreteKsdj entity = new ConcreteKsdj();
        if (object == null) {
            return JsonUtils.beanToObject(entity);
        }
        if (object instanceof String) {
            entity = JsonUtils.getObject((String) object, ConcreteKsdj.class);
        } else if (object instanceof JSONObject) {
            entity = JsonUtils.getObject((JSONObject) object, ConcreteKsdj.class);
        }
        return JsonUtils.beanToObject(entity);
    }

    /**
     * 校验必检的
     *
     * @param objJson
     * @return
     */
    public static String checkIsMust(JSONObject objJson, String name) {
        if (objJson.isEmpty()) {
            return null;
        }
        ConcreteKsdj entity = JsonUtils.getObject(objJson, ConcreteKsdj.class);
        if (StringUtils.isBlank(entity.getSsksdj()) || "null".equals(entity.getSsksdj())) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        return null;
    }
}
